package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.PullTeaNetsignMapper;
import com.yunhai.device.service.PullTeaNetsignService;
import com.yunhai.model.entity.dms.DmsPullTeaNetsignEntity;
import com.yunhai.model.vo.dms.DmsPullTeaNetsignQuery;
import com.yunhai.model.vo.dms.DmsPullTeaNetsignVo;
import org.apache.commons.beanutils.PropertyUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class PullTeaNetsignServiceImpl implements PullTeaNetsignService {

    @Resource
    private PullTeaNetsignMapper pullTeaNetsignMapper;

    /**
     * 获取 PullTeaNetsign 分页列表
     */
    @Transactional
    public IPage getPullTeaNetsignPagination(PaginationVo paginationVo, DmsPullTeaNetsignQuery dmsPullTeaNetsignQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<DmsPullTeaNetsignEntity> lqs = new LambdaQueryWrapper();
        pullTeaNetsignMapper.selectPage(page, lqs);

        List<DmsPullTeaNetsignEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 PullTeaNetsign 所有数据
     *
     */
    @Transactional
    public List<DmsPullTeaNetsignEntity> getPullTeaNetsignAllList( DmsPullTeaNetsignQuery dmsPullTeaNetsignQuery ) throws Exception {

        LambdaQueryWrapper<DmsPullTeaNetsignEntity> lqs = new LambdaQueryWrapper();
        List<DmsPullTeaNetsignEntity> list = pullTeaNetsignMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 PullTeaNetsign 详情
     */
    @Transactional
    public DmsPullTeaNetsignEntity getPullTeaNetsignDetail( Long id) throws Exception {

        DmsPullTeaNetsignEntity dmsPullTeaNetsignEntity = pullTeaNetsignMapper.selectById(id);
        return dmsPullTeaNetsignEntity;
    }


    /**
     * 新增 PullTeaNetsign
     * */
    @Transactional
    public void addPullTeaNetsign(DmsPullTeaNetsignVo dmsPullTeaNetsignVo) throws Exception {

        DmsPullTeaNetsignEntity dmsPullTeaNetsignEntity = new DmsPullTeaNetsignEntity();
        ReflectionCopy.copyProperties( dmsPullTeaNetsignEntity, dmsPullTeaNetsignVo );
        dmsPullTeaNetsignEntity.setCreateTime(new Date());
        dmsPullTeaNetsignEntity.setIsDeleted(0);
        pullTeaNetsignMapper.insert(dmsPullTeaNetsignEntity);
        return;
    }


    /**
     * 更新 PullTeaNetsign
     * */
    @Transactional
    public void updatePullTeaNetsign( DmsPullTeaNetsignVo dmsPullTeaNetsignVo) throws Exception {

        if( dmsPullTeaNetsignVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        DmsPullTeaNetsignEntity dmsPullTeaNetsignEntity = new DmsPullTeaNetsignEntity();
        ReflectionCopy.copyProperties( dmsPullTeaNetsignEntity, dmsPullTeaNetsignVo );
        pullTeaNetsignMapper.updateById(dmsPullTeaNetsignEntity);
        return;
    }

    /**
     * 删除 PullTeaNetsign
     * */
    @Transactional
    public void batchRemovePullTeaNetsign( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        pullTeaNetsignMapper.deleteBatchIds(ids);
    }

}